package com.dgut.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CreateThread3 {
    public static void main(String[] args) {
        Callable call = new MyCallable();
        FutureTask<String> task = new FutureTask<>(call);
        Thread t = new Thread(task);
        t.start();
        try {
            String s = task.get(); // 获取call方法返回的结果（正常/异常结果）
            System.out.println(s);
            System.out.println("ss");
        }  catch (Exception e) {
            e.printStackTrace();
        }
    }

}
class MyCallable implements Callable<String> {
    @Override//重写线程任务类方法
    public String call() throws Exception {
        Thread.sleep(1000);
        return Thread.currentThread().getName() + "->" + "Hello World";
    }
}
